package com.tledu.mvc02.controller;

import com.alibaba.fastjson.JSONObject;
import com.tledu.mvc02.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 测试参数的获取
 * @author Antg
 * @date 2021/8/11  22:33
 */
@RestController
@RequestMapping("/test02")
public class UserController2 {
    //指定必要的参数name和必要的请求头token
    @GetMapping(value = "/m1",params = {"name"},headers = {"token"})
    public JSONObject m1(String name){
        System.out.println(name);
        return null;
    }
    //指定必要的请求头
    @GetMapping(value = "/m2",headers = {"token"})
    public JSONObject m2(String name){
        System.out.println(name);
        return null;
    }
    //获取基本类型的参数
    @GetMapping(value = "/m3")
    public JSONObject m3(String name){
        System.out.println(name);
        return null;
    }
    //获取包装类型并返回
    @PostMapping("/m4")
    public JSONObject m4(User user){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("user",user);
        return jsonObject;
    }
    //给参数指定别名
    @GetMapping("/m5")
    public String m5(@RequestParam("aaa") String username){
        return username;
    }
    //接收json数据
    @PostMapping("/m6")
    public JSONObject m6(@RequestBody User user){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("user",user);
        return jsonObject;
    }



}
